package com.easyCms.base.web;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.easyCms.base.common.RespCode;
import com.easyCms.base.entity.BsSystemInfo;
import com.easyCms.base.entity.ResultBean;
import com.easyCms.base.service.BsSystemInfoSV;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.easyCms.base.busi.BsNavBusi;
import com.easyCms.base.busi.vo.BsNavVO;
import com.easyCms.base.utils.ControllerUtils;
import com.easyCms.base.utils.JsonUtils;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/adminManageData")
public class AdminFrameDataController {
    private static Logger logger = LoggerFactory.getLogger(AdminFrameDataController.class);

    @Autowired
    private BsNavBusi bsNavBusi;
    @Autowired
    private BsSystemInfoSV bsSystemInfoSV;

    /*
     * 初始化左侧导航
     *
     */
    @RequestMapping(value = "/initLeftTreeNav", method = RequestMethod.GET)
    public void initLeftTreeNav(PrintWriter printWriter, HttpServletResponse response,
                                @RequestParam(name = "authType", required = false) Integer authType) {
        try {
            List<BsNavVO> initNav = bsNavBusi.initNav(authType);
            logger.info("菜单为" + JsonUtils.toJson(initNav));
            response.setHeader("Content-type", "text/html;charset=UTF-8");
            ControllerUtils.output(printWriter, initNav, logger, false);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    /*
     * 初始化配置信息
     *
     */
    @RequestMapping(value = "/initConfigInfo", method = RequestMethod.GET)
    public @ResponseBody
    ResultBean initConfigInfo(PrintWriter printWriter, HttpServletResponse response) {
        ResultBean resultBean = new ResultBean();
        try {
            BsSystemInfo systemInfo = bsSystemInfoSV.findValid();
            resultBean.setCode(RespCode.SUCCESS);
            resultBean.setData(systemInfo);
            return resultBean;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return resultBean;
    }

}
